package com.janj.Phone1Plus;
//测试类

import com.janj.Phone3Plus.JDBCUtils3;
import com.janj.Phone4Plus.JDBCUtils4;
import com.janj.jdbc2.Phone;

import java.sql.*;
import java.util.ArrayList;

public class DemoPhone {
    public static void main(String[] args) {
          
        //1.定义CSR
        Connection conn = null;
        Statement stat = null;
        ResultSet resu = null;

        //2.获取到 C-> S -> R 执行查询语句
        String sql = "SELECT * FROM phone";

        conn = JDBCUtils3.getConnection();

        try {
            stat = conn.createStatement();
            resu = stat.executeQuery(sql);

            //3.循环遍历,查询结果集
            while (resu.next()) {
                int id = resu.getInt("id");
                String name = resu.getString("name");
                int price = resu.getInt("price");
                System.out.println(id + "\t" + name + "\t" + price);
            }
            //释放资源
            JDBCUtils4.close(conn, stat, resu);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
